package com.qst.express.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qst.express.entity.Express;
import com.qst.express.entity.Sum;
import com.qst.express.mapper.SumMapper;
import com.qst.express.service.ExpressService;
import com.qst.express.service.SumService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mjh
 * @since 2022-10-25
 */
@Service
public class SumServiceImpl extends ServiceImpl<SumMapper, Sum> implements SumService {
    @Autowired
    ExpressService expressService;
    @Override
    @Transactional
    public List<Map<String, Integer>> exressSum() {
        QueryWrapper<Express> wrapper = new QueryWrapper<Express>();
        wrapper.eq("status","0");
        int count = expressService.count(wrapper);
        System.out.println(count);
        QueryWrapper<Sum> wrapper2 = new QueryWrapper<Sum>();
        wrapper2.eq("address","张家界");

        Sum sum = new Sum();
        sum.setCount(count+"");
        // 更新
        baseMapper.update(sum,wrapper2);
        // 查询
        List<Map<String, Integer>> data = baseMapper.exressSum();
        return data;
    }
}
